/**
 * 
 */
package com.p2p.front.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.p2p.front.dal.dao.TenderAutoSettingDao;
import com.p2p.front.dal.model.TenderAutoSetting;
import com.p2p.front.service.TenderAutoSettingService;

/**
 * @author ricky
 *
 */
@Service("tenderAutoSettingService")
public class TenderAutoSettingServiceImpl implements TenderAutoSettingService {

	@Resource
	TenderAutoSettingDao tenderAutoSettingDao;
	
	/* (non-Javadoc)
	 * @see com.p2p.user.service.TenderAutoSettingService#getByUserId(java.lang.String)
	 */
	@Override
	public TenderAutoSetting getByUserId(String userId) {
		// TODO Auto-generated method stub
		return tenderAutoSettingDao.getByUserId(userId);
	}

	/* (non-Javadoc)
	 * @see com.p2p.user.service.TenderAutoSettingService#saveSetting(com.p2p.user.dal.model.TenderAutoSetting)
	 */
	@Override
	public void saveSetting(TenderAutoSetting tenderAutoSetting) {
		 //.replace(tenderAutoSetting)
		if(tenderAutoSetting.getId()==null){
			insert(tenderAutoSetting);
		}else{
			tenderAutoSettingDao.update(tenderAutoSetting);
		}
		
	}
	private void insert(TenderAutoSetting tenderAutoSetting){
		try {
			tenderAutoSettingDao.insert(tenderAutoSetting);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	@Override
	public int updateStatus(TenderAutoSetting tenderAutoSetting) {
		
		if(tenderAutoSetting.getId()==null){
			insert(tenderAutoSetting);
		}
		return tenderAutoSettingDao.updateStatus(tenderAutoSetting);
		
	}

}
